package P09_ThreadPool线程池;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class P02_CustomizedThreadPool {
    public static void main(String[] args) {
        ThreadPoolExecutor pool1 = new ThreadPoolExecutor(2, 5, 2L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(15), Executors.defaultThreadFactory(), new ThreadPoolExecutor.CallerRunsPolicy());
        // 10个顾客请求
        try {
            for (int i = 0; i < 20; i++) {
                int finalI = i;
                pool1.execute(() ->{
                    System.out.println(Thread.currentThread().getName() + "办理业务" + (finalI +1));
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                });
            }
        } finally {
            pool1.shutdown();
        }
    }
}
